package com.meiqiongproperty.yiguanjia.fragment.home.health;

import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.meiqiongproperty.yiguanjia.R;
import com.meiqiongproperty.yiguanjia.activity.GenericFragmentActivity;
import com.meiqiongproperty.yiguanjia.databinding.FreeMedicalLayoutBinding;
import com.meiqiongproperty.yiguanjia.fragment.BaseFragment;
import com.meiqiongproperty.yiguanjia.ui.adbanner.animations.DescriptionAnimation;
import com.meiqiongproperty.yiguanjia.ui.adbanner.indicators.PagerIndicator;
import com.meiqiongproperty.yiguanjia.ui.adbanner.slidertypes.BaseSliderView;
import com.meiqiongproperty.yiguanjia.ui.adbanner.slidertypes.TextSliderView;
import com.meiqiongproperty.yiguanjia.ui.adbanner.viewpagerswitchanimation.SliderLayout;
import com.meiqiongproperty.yiguanjia.utils.LogUtil;
import com.meiqiongproperty.yiguanjia.utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * author: Administrator
 * date: 2017/5/21.
 * package:com.meiqiongproperty.yiguanjia.fragment.home.health
 */

public class PhysicalExaminationFragment extends BaseFragment {
    FreeMedicalLayoutBinding binding;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.free_medical_layout, container, false);
        binding.setClick(this);
        binding.navigation.setTitle("健康医疗");
        binding.navigation.setLeftClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendKeyBackEvent();
            }
        });
        binding.navigation.setRightText("个人档案");
        binding.navigation.setRightClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GenericFragmentActivity.start(getActivity(), HealthyInfoFragment.class, new Bundle());
            }
        });
        Utils.spannableText(binding.text, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.d("你妹的================>点你怎么了");
            }
        }, 0, binding.text.getText().toString().length() - 2, Spanned.SPAN_INCLUSIVE_INCLUSIVE, getActivity().getResources().getColor(R.color.yihealth_header_color));

        getData1();
        return binding.getRoot();
    }

    public void getData1() {
        final List<Integer> img = new ArrayList<>();
        img.add(R.mipmap.banner_healthy);
        img.add(R.mipmap.registration_appointment);
        img.add(R.mipmap.banner_healthy);
        img.add(R.mipmap.product_detail);

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (img.size() <= 1) {
                    binding.slider.stopAutoCycle();
                } else {
                    binding.slider.startAutoCycle();
                }
            }
        }, 3000);

        if (img.size() <= 1) {
            binding.slider.setBottomIndicator(View.GONE);
            binding.slider.getPagerIndicator().setIndicatorVisibility(PagerIndicator.IndicatorVisibility.Invisible);
        } else {
            binding.slider.getPagerIndicator().setDefaultIndicatorColor(getResources().getColor(R.color.physicalexamination_cycler_point), Color.argb(66, 255, 255, 255));
        }


        for (int i = 0; i < img.size(); i++) {
            TextSliderView textSliderView = new TextSliderView(getActivity(), img, 1);
            // initialize a SliderLayout
            textSliderView
                    .image(img.get(i))
                    .setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() {
                        @Override
                        public void onSliderClick(BaseSliderView slider) {

                        }
                    });

            binding.slider.addSlider(textSliderView);
        }
        // binding.customIndicator.setColor(Color.rgb(19, 181, 221),Color.argb(33, 255, 255, 255));
        binding.slider.setPresetTransformer(SliderLayout.Transformer.Stack);
        binding.slider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
        binding.slider.setCustomAnimation(new DescriptionAnimation());

    }

    public void openMemberClick(View view) {
        GenericFragmentActivity.start(getActivity(), OpenMemberFragment.class, new Bundle());
    }

    @Override
    public void onResume() {
        super.onResume();
    }
}
